package qianlong.practice.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import qianlong.practice.entity.User;
import qianlong.practice.service.UserService;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/users")
@Api(tags = "用户控制器")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping
    @ApiOperation("插入用户信息")
    public int insert(@RequestBody User user){
        return userService.insert(user);
    }

    @PutMapping
    @ApiOperation("修改用户信息")
    public int update(@RequestBody User user){
        return userService.update(user);
    }

    @DeleteMapping(value = "/{id}")
    @ApiOperation("删除用户信息")
    public int delete(@PathVariable(value = "id",required = true) Integer id){
        return userService.delete(id);
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("得到一个用户信息")
    public User getOne(@PathVariable(value = "id",required = true) Integer id){
        return userService.getOne(id);
    }

    @GetMapping("")
    @ApiOperation("得到所有用户信息")
    public List<User> getList(User user){
        return userService.getList(user);
    }
}
